package com.example.zbh.lessona.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.zbh.lessona.R;
import com.example.zbh.lessona.entity.ActivityInfo;

import java.util.List;

/**
 * Created by nanchaodong on 15/12/31.
 */
public class MainPagerAdapter extends BaseAdapter {
    private List<ActivityInfo> list;

    public void addData(List<ActivityInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public boolean isLength() {
        return list != null && list.size() > 0;
    }

    @Override
    public int getCount() {
        return isLength() ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.adapter_main_pager, null);
            holder = new ViewHolder();
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView = (TextView) convertView.findViewById(R.id.textView);
        holder.textView.setText(list.get(position).toString());
        return convertView;
    }

    class ViewHolder {
        TextView textView;

    }
}
